﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAplicaciones1;


namespace interfaz
{
    public partial class FormItem : Form
    {
        private Sistema sistema;

        public FormItem()
        {
            InitializeComponent();
            sistema = Sistema.GetSistema();
        }
        private void fieldsControl(object sender, EventArgs e)
        {
            if (rbnLibro.Checked)
            {
                groupMagazine.Visible = false;
                groupCd.Visible = false;
                groupDvd.Visible = false;
                groupLibro.Visible = true;
                groupMagazine.Visible = false;
                lblErrorISBN.Visible = true;
                lblErrorAutor.Visible = true;
                lblErrorArtistaCd.Visible = false;
                lblErrorNCanciones.Visible = false;
                lblErrorArtistaDvd.Visible = false;
                lblErrorDuracion.Visible = false;
            }
            if (rbnCd.Checked)
            {
                
                groupDvd.Visible = false;
                groupLibro.Visible = false;
                groupCd.Visible = true;
                groupMagazine.Visible = false;
                lblErrorISBN.Visible = false;
                lblErrorAutor.Visible = false;
                lblErrorArtistaCd.Visible = true;
                lblErrorNCanciones.Visible = true;
                lblErrorArtistaDvd.Visible = false;
                lblErrorDuracion.Visible = false;
            }
            if (rbnDvd.Checked)
            {
                groupCd.Visible = false;
                groupDvd.Visible = true;
                groupLibro.Visible = false;
                groupMagazine.Visible = false;
                lblErrorISBN.Visible = false;
                lblErrorAutor.Visible = false;
                lblErrorArtistaCd.Visible = false;
                lblErrorNCanciones.Visible = false;
                lblErrorArtistaDvd.Visible = true;
                lblErrorDuracion.Visible = true;
            }
            if (rbnMagazine.Checked)
            {
                groupDvd.Visible = false;
                groupLibro.Visible = false;
                groupCd.Visible = false;
                groupMagazine.Visible = true;
            }
            
        }
         
        private void btnSiguiente_Click(object sender, EventArgs e)
        {          
          Item itemCreated = null;
          try{
                if (rbnLibro.Checked)                
                   itemCreated = sistema.crearLibro(txtNombre.Text, txtPrecio.Text,txtCosto.Text,txtISBN.Text,txtAutor.Text);                
                
                if (rbnCd.Checked)
                   itemCreated = sistema.crearCD(txtNombre.Text, txtPrecio.Text, txtCosto.Text, txtArtistaCd.Text, txtNCanciones.Text);
                
                if (rbnDvd.Checked)
                   itemCreated = sistema.crearDvd(txtNombre.Text, txtPrecio.Text, txtCosto.Text, txtArtistaDvd.Text, txtDuracion.Text);

                if (rbnMagazine.Checked)
                    itemCreated = sistema.crearMagazine(txtNombre.Text, txtPrecio.Text, txtCosto.Text, txtCodigo.Text, txtNroEdicion.Text,txtCantPaginas.Text);

                if (itemCreated != null)
                {
                    FormAgregados fagregados = new FormAgregados(itemCreated);
                    fagregados.Show();
                    this.Visible = false;
                }else
                    MessageBox.Show("Debe completar todos los datos para continuar", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            FormMenu menu = new FormMenu();
            menu.Show();
            this.Visible = false;
        }

        private void FormItem_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }       

         
    }
}
